package com.takeeasy.platform.util;

import org.safehaus.uuid.UUID;
import org.safehaus.uuid.UUIDGenerator;


public class UuidGenerator {
	
	/**
	 * 生成32位UUID，返回类型为String（32）
	 * @return
	 */
	public synchronized static String getUUID(){
		
		UUIDGenerator UUIDgenerator = UUIDGenerator.getInstance();
    	UUID uuid = UUIDgenerator.generateRandomBasedUUID();
    	String result = uuid.toString().replaceAll("-", "");   	
 	  
  	    return result;
	}
	
	/**
     * 获得long型内码
     * @return long型唯一内码
     */
    static synchronized public long getLongId(){
        return System.currentTimeMillis();
    }
    

	   /*
     * Demonstraton and self test of class
     */
    public static void main(String args[]) {
    	/**
    	 *test getLongId
    	 */
    	for (int i=0;i<10;i++){
    		System.out.println(i+"   getLongId=" + getLongId()); 
    	}
    	/**
    	 * test uuid generate
    	 */
        for (int i=0; i< 100; i++) {
        	System.out.println(i+"   getUUID=" + getUUID());
        }
    }
}
